USE [AdventureWorksLT2012]
GO

/****** Object:  StoredProcedure [dbo].[CustomerAdd]    Script Date: 6/11/2014 10:32:58 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Michael Blumenthal
-- Create date: June 9, 2014
-- Description:	Update a customer
-- =============================================
CREATE PROCEDURE [dbo].[CustomerUpdate] 
	-- Add the parameters for the stored procedure here
@CustomerID int,
@Title nvarchar(8),
@FirstName nvarchar(50),
@LastName nvarchar(50),
@CompanyName nvarchar(128),
@SalesPerson nvarchar(256),
@EmailAddress nvarchar(50),
@Phone nvarchar(25),
@AddressLine1 nvarchar(60),
@City nvarchar(30),
@StateProvince nvarchar(50),
@CountryRegion nvarchar(50),
@PostalCode nvarchar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

DECLARE @NameStyle bit = 0;
DECLARE @identityTable table( ID int, TableName varchar(10));  
DECLARE @AddressID int;


UPDATE [SalesLT].[Customer]
   SET [NameStyle] = 0
      ,[Title] = @Title
      ,[FirstName] = @FirstName
      ,[LastName] = @LastName
      ,[CompanyName] = @CompanyName
      ,[SalesPerson] = @SalesPerson
      ,[EmailAddress] = @EmailAddress
      ,[Phone] = @Phone
      ,[ModifiedDate] = GETDATE()
 WHERE CustomerID = @CustomerID

SELECT @AddressID = AddressID
FROM SalesLT.CustomerAddress
where CustomerID = @CustomerID

UPDATE [SalesLT].[Address]
   SET [AddressLine1] = @AddressLine1
      ,[City] = @City
      ,[StateProvince] = @StateProvince
      ,[CountryRegion] = @CountryRegion
      ,[PostalCode] = @PostalCode
      ,[ModifiedDate] = GETDATE()
 WHERE AddressID = @AddressID


END
GO


